<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);

namespace app\model\order;

use app\model\user\User;
use crmeb\basic\BaseModel;
use crmeb\traits\ModelTrait;
use think\Model;

class Orders extends BaseModel
{
    use ModelTrait;

    /**
     * 数据表主键
     * @var string
     */
    protected $pk = 'id';

    /**
     * 模型名称
     * @var string
     */
    protected $name = 'orders';

    /**
     * 订单状态名常量
     */
    public const ORDER_STATUS_NAME = [
        '0' => '待付款',
        '1' => '待发货',
        '2' => '待收货',
        '3' => '已完成',
        '4' => '已取消',
        '5' => '已关闭',
    ];

    /**
     * 订单支付方式常量
     */
    public const ORDER_PAY_TYPE_NAME = [
        '1' => '支付宝',
        '2' => '微信',
        '3' => 'Grab'
    ];

    /**
     * @return \think\model\relation\HasOne
     * 订单用户关联
     */
    public function user()
    {
        return $this->hasOne(User::class, 'uid', 'uid')->bind(['nickname']);
    }

    /**
     * @return \think\model\relation\HasMany
     * 订单商品表关联
     */
    public function orderItems()
    {
        return $this->hasMany(OrderItems::class, 'order_id', 'id');
    }
}

